#ifndef _COMMIT_HPP
#define _COMMIT_HPP 1

#include <boost/shared_ptr.hpp>

#include "../constants.hpp"

#include "../Parameters.hpp"

#include "Digest.hpp"
#include "HistoryDigest.hpp"
#include "MacArrayMessage.hpp"
#include "VerifiedMessageBase.hpp"

//#include "Prepare.hpp" //forward declared below

namespace BFT
{
	namespace order
	{
		namespace messages
		{
		
			class Prepare; //forward declaration of class Prepare to avoid circular dependencies
			
			class Commit : public BFT::messages::MacArrayMessage
			{
				public:
				
				Commit(uint32_t _view, uint32_t _seq, boost::shared_ptr<BFT::messages::HistoryDigest> _pphash, 
					uint32_t _sendingReplica);
				
				Commit(boost::shared_ptr<Prepare> _p, uint32_t _sendingReplica);
				
				Commit(boost::shared_ptr<char> _bytes, int _bytes_size);

				
				bool equals(boost::shared_ptr<Commit> _other_c);
				//bool matches(boost::shared_ptr<BFT::messages::VerifiedMessageBase> _other_vmb);
				
				uint32_t getView(); //inlined
				uint32_t getSeqNo(); //inlined
				uint32_t getSendingReplica(); //inlined
				
				boost::shared_ptr<BFT::messages::HistoryDigest> getPrePrepareHash(); //inlined
				
				void printInfo();

				protected:
				
				uint32_t viewNo;
				uint32_t seqNo;
				
				boost::shared_ptr<BFT::messages::HistoryDigest> ppHash;
			
				private:
				
				static uint32_t computeSize(boost::shared_ptr<BFT::messages::HistoryDigest> _pphash); //inlined	
			
			};
			
						
			inline uint32_t Commit::getView() {return viewNo;}
			inline uint32_t Commit::getSeqNo() {return seqNo;}
			inline uint32_t Commit::getSendingReplica() {return getSender();}
			inline uint32_t Commit::computeSize(boost::shared_ptr<BFT::messages::HistoryDigest> _pphash) {return VIEW_NUMBER_SIZE + SEQUENCE_NUMBER_SIZE + DIGEST_SIZE;}			
			inline boost::shared_ptr<BFT::messages::HistoryDigest> Commit::getPrePrepareHash() {return ppHash;} 
		}
	}
}

#endif
